package it.enricod.jcontextfree.model.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.inject.Inject;

import it.enricod.jcontextfree.engine.model.IProgram;
import it.enricod.jcontextfree.engine.samples.IProgramCatalogEntry;
import it.enricod.jcontextfree.engine.samples.IProgramsCatalog;
import it.enricod.jcontextfree.model.IProgramPM;
import it.enricod.jcontextfree.model.IProgramsLoader;

public class SamplesLoader implements IProgramsLoader {

	private IProgramsCatalog programsCatalog;

	@Inject
	public SamplesLoader(IProgramsCatalog programsCatalog) {
		this.programsCatalog = programsCatalog;
	}

	public List<IProgramPM> getPrograms() {
		List<IProgramPM> result = new ArrayList<IProgramPM>();
		Collection<IProgramCatalogEntry> samplesEntries = programsCatalog.getEntries();
		for (IProgramCatalogEntry programCatalogEntry : samplesEntries) {
			IProgram aProgram = programCatalogEntry.getProgram();
			IProgramPM aProgramPM = new ProgramPM(programCatalogEntry.getId(), aProgram);
			result.add(aProgramPM);
		}
		return result;
	}

	public IProgramPM getWelcomeProgram() {
		IProgramCatalogEntry catalogEntry = programsCatalog.getEntry("WELCOME");
		IProgramPM result = new ProgramPM(catalogEntry.getId(), catalogEntry.getProgram());
		return result;
	}

}
